package br.trainee.web.componentes;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import br.trainee.web.util.ResponseWrapper;

public class DatepickerTag extends BodyTagSupport{	
	
	private static final long serialVersionUID = 1L;
	
	private String idDatepicker;
	private String form;
	private String labelFor;
	private String labelText;
	private String inputClass;
	private String inputName;
	
	
	private String showOn;
	private String showOtherMonths;
	private String changeMonth;
	private String changeYear;
	private String showAnim;
	private String beforeShowDay;
	private String appendText;
	private String hideIfNoPrevNext;
	private String maxDate;
	private String dateFormat;
	private String dayNames;
	private String dayNamesMin;
	private String monthNames;
	private String monthNamesShort;
	private String setDate;
	private String onClose;
	
	
	@Override
	public int doEndTag() throws JspException {
		
		String corpo = getBodyContent().getString();
		
		JspWriter saida = pageContext.getOut();
		
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
		
		request.setAttribute("idDatepicker", idDatepicker);
		request.setAttribute("form", form);
		request.setAttribute("labelFor", labelFor);
		request.setAttribute("labelText", labelText);
		request.setAttribute("inputClass", inputClass);
		request.setAttribute("inputName", inputName);
		
		
		request.setAttribute("corpo", corpo);
		request.setAttribute("showOn", showOn);
		request.setAttribute("showOtherMonths", showOtherMonths);
		request.setAttribute("changeMonth", changeMonth);
		request.setAttribute("changeYear", changeYear);
		request.setAttribute("showAnim", showAnim);
		request.setAttribute("beforeShowDay", beforeShowDay);
		request.setAttribute("appendText", appendText);
		request.setAttribute("hideIfNoPrevNext", hideIfNoPrevNext);
		request.setAttribute("maxDate", maxDate);
		request.setAttribute("dateFormat", dateFormat);
		request.setAttribute("dayNames", dayNames);
		request.setAttribute("dayNamesMin", dayNamesMin);
		request.setAttribute("monthNames", monthNames);
		request.setAttribute("monthNamesShort", monthNamesShort);
		request.setAttribute("setDate", setDate);
		request.setAttribute("onClose", onClose);
		
		ResponseWrapper responseWrapper = new ResponseWrapper(response);
		
		RequestDispatcher req = request.getRequestDispatcher("/resources/componentes-jsp/datepicker.jsp");
		
		try {
			
			req.include(request, responseWrapper);
			//Nessa linha a interpretação já foi feita!!
			String conteudoComponente = responseWrapper.getString();
			
			saida.println(conteudoComponente);
			
		} catch (ServletException | IOException e) {
			
			e.printStackTrace();
		}
		
		return super.doEndTag();
	}


	public String getIdDatepicker() {
		return idDatepicker;
	}

	public void setIdDatepicker(String idDatepicker) {
		this.idDatepicker = idDatepicker;
	}


	public String getChangeYear() {
		return changeYear;
	}


	public void setChangeYear(String changeYear) {
		this.changeYear = changeYear;
	}


	public String getShowOn() {
		return showOn;
	}


	public void setShowOn(String showOn) {
		this.showOn = showOn;
	}


	public String getShowOtherMonths() {
		return showOtherMonths;
	}


	public void setShowOtherMonths(String showOtherMonths) {
		this.showOtherMonths = showOtherMonths;
	}


	public String getChangeMonth() {
		return changeMonth;
	}


	public void setChangeMonth(String changeMonth) {
		this.changeMonth = changeMonth;
	}


	public String getShowAnim() {
		return showAnim;
	}


	public void setShowAnim(String showAnim) {
		this.showAnim = showAnim;
	}


	public String getBeforeShowDay() {
		return beforeShowDay;
	}


	public void setBeforeShowDay(String beforeShowDay) {
		this.beforeShowDay = beforeShowDay;
	}


	public String getAppendText() {
		return appendText;
	}


	public void setAppendText(String appendText) {
		this.appendText = appendText;
	}

	public String getMaxDate() {
		return maxDate;
	}


	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}


	public String getDateFormat() {
		return dateFormat;
	}


	public void setDateFormat(String dateFormat) {
		this.dateFormat = dateFormat;
	}


	public String getDayNames() {
		return dayNames;
	}


	public void setDayNames(String dayNames) {
		this.dayNames = dayNames;
	}


	public String getDayNamesMin() {
		return dayNamesMin;
	}


	public void setDayNamesMin(String dayNamesMin) {
		this.dayNamesMin = dayNamesMin;
	}


	public String getMonthNames() {
		return monthNames;
	}


	public void setMonthNames(String monthNames) {
		this.monthNames = monthNames;
	}


	public String getMonthNamesShort() {
		return monthNamesShort;
	}


	public void setMonthNamesShort(String monthNamesShort) {
		this.monthNamesShort = monthNamesShort;
	}


	public String getSetDate() {
		return setDate;
	}


	public void setSetDate(String setDate) {
		this.setDate = setDate;
	}


	public String getHideIfNoPrevNext() {
		return hideIfNoPrevNext;
	}


	public void setHideIfNoPrevNext(String hideIfNoPrevNext) {
		this.hideIfNoPrevNext = hideIfNoPrevNext;
	}


	public String getOnClose() {
		return onClose;
	}


	public void setOnClose(String onClose) {
		this.onClose = onClose;
	}


	public String getForm() {
		return form;
	}


	public void setForm(String form) {
		this.form = form;
	}


	public String getLabelFor() {
		return labelFor;
	}


	public void setLabelFor(String labelFor) {
		this.labelFor = labelFor;
	}


	public String getLabelText() {
		return labelText;
	}


	public void setLabelText(String labelText) {
		this.labelText = labelText;
	}


	public String getInputClass() {
		return inputClass;
	}


	public void setInputClass(String inputClass) {
		this.inputClass = inputClass;
	}


	public String getInputName() {
		return inputName;
	}


	public void setInputName(String inputName) {
		this.inputName = inputName;
	}
	
	

}
